package com.yzd.learnjava.arrays;

import java.util.Arrays;
import java.util.Random;

import com.yzd.learnjava.util.Generated;
import com.yzd.learnjava.util.Generator;
import com.yzd.learnjava.util.Print;

public class CompType implements Comparable<CompType>{
	int i ;
	int j ;
	private static int count = 1 ;
	public CompType(int n1 , int n2) {
		this.i = n1 ;
		this.j = n2 ;
	}
	
	public String toString() {
		String result = "[i = " + i + ", j = " + j + "]";
		if(count++ % 3 == 0) {
			result += "\n";
		}
		return result;
	}
	public int compareTo(CompType rv) {
		return (i < rv.i ? -1 : (i == rv.i ? 0 : 1));
	}
	
	private static Random r = new Random(47);
	public static Generator<CompType> generator(){
		return new Generator<CompType>() {
			public CompType next() {
				return new CompType(r.nextInt(100), r.nextInt(100));
			}
		};
	}
	
	public static void main(String[] args) {
		CompType[] a = Generated.array(new CompType[12], generator());
		Print.print("before sorting : " + Arrays.toString(a));
		Arrays.sort(a);
		Print.print("after sorting : " + Arrays.toString(a));
	}
	
}















